package com.bootdo.appsystem.service.impl;

import com.bootdo.app.utils.returnresponse.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.appsystem.dao.ShipaddressDao;
import com.bootdo.appsystem.domain.ShipaddressDO;
import com.bootdo.appsystem.service.ShipaddressService;


@Service
public class ShipaddressServiceImpl implements ShipaddressService {
    @Autowired
    private ShipaddressDao shipaddressDao;

    @Override
    public ShipaddressDO get(Integer shipid) {
        return shipaddressDao.get(shipid);
    }

    @Override
    public List<ShipaddressDO> list(Map<String, Object> map) {
        return shipaddressDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return shipaddressDao.count(map);
    }

    @Override
    public int save(ShipaddressDO shipaddress) {
        return shipaddressDao.save(shipaddress);
    }

    @Override
    public int update(ShipaddressDO shipaddress) {
        return shipaddressDao.update(shipaddress);
    }

    @Override
    public int remove(Integer shipid) {
        return shipaddressDao.remove(shipid);
    }

    @Override
    public int batchRemove(Integer[] shipids) {
        return shipaddressDao.batchRemove(shipids);
    }

    @Override
    public ShipaddressDO getUserDefault(Integer uid, Integer isdefault) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("isdefault", isdefault);
        List<ShipaddressDO> list = this.list(map);
        if(list.size() < 1 || list == null){
            return null;
        }else {
            return list.get(0);
        }
    }

    @Override
    public ServerResponse updateOtherDefault(Integer uid) {
        try {
            shipaddressDao.updateOtherDefault(uid);
        } catch (RuntimeException e) {
            return ServerResponse.createByError();
        }
        return ServerResponse.createBySuccess();
    }

}
